package com.demo.controller;

import com.demo.pojo.Notice;
import com.demo.pojo.ResultVO;
import com.demo.service.NoticeService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/notice")
public class NoticeController {

    @Resource
    private NoticeService noticeService;

    // 查询公告列表（支持筛选：全部、已读、未读）
    @GetMapping("/list")
    public ResultVO<List<Notice>> getNoticeList(@RequestParam(value = "readStatus", required = false) Integer readStatus) {
        return noticeService.getNoticeList(readStatus);
    }

    // 查询公告详情
    @GetMapping("/{id}")
    public  ResultVO<Notice> getNoticeDetail(@PathVariable Long id) {
        Notice notice = noticeService.getNoticeDetail(id);
        // 点击详情时标记为已读（可选逻辑）
        noticeService.markAsRead(notice);
        return ResultVO.success(notice);
    }

    // 新增公告（示例，实际可用于后台管理）
    @PostMapping("/add")
    public ResultVO<?>addNotice(@RequestBody Notice notice) {
        noticeService.addNotice(notice);
        return ResultVO.success("新增成功");
    }
}